﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace xyw
{
    public partial class Reg : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        XYW.BLL.Classes bllClass = new XYW.BLL.Classes();
        private void BindData()
        {
            
            this.ddl_Year.DataSource = bllClass.GetYearList();
            this.ddl_Year.DataTextField = "year";
            this.ddl_Year.DataValueField = "year";
            this.ddl_Year.DataBind();

            string year = ddl_Year.SelectedValue;
            this.ddl_College.DataSource = bllClass.GetCollegeList(year);
            this.ddl_College.DataTextField = "collegeName";
            this.ddl_College.DataValueField = "collegeName";
            this.ddl_College.DataBind();

            string collegeName = this.ddl_College.SelectedValue;
            this.ddl_Class.DataSource = bllClass.GetClassList(year, collegeName);
            this.ddl_Class.DataTextField = "className";
            this.ddl_Class.DataValueField = "ID";
            this.ddl_Class.DataBind();

            
        }//zjsruadmin&)#$**@(

        protected void Button1_Click(object sender, EventArgs e)
        {
            XYW.Model.Users modelUser = new XYW.Model.Users();
            XYW.BLL.Users bllUser = new XYW.BLL.Users();
            modelUser.isSuper = 0;
            modelUser.name = this.txt_Name.Text.Trim();
            modelUser.sex = this.ddl_Sex.SelectedValue;
            modelUser.classId = int.Parse(this.ddl_Class.SelectedValue);
            modelUser.number = this.txt_Number.Text.Trim();
            modelUser.passWord = this.txt_Password.Text.Trim();
            bllUser.Add(modelUser);
            Response.Redirect("./Reg2.aspx");
        }

        protected void ddl_Year_SelectedIndexChanged(object sender, EventArgs e)
        {
            string year = ddl_Year.SelectedValue;
            this.ddl_College.DataSource = bllClass.GetCollegeList(year);
            this.ddl_College.DataTextField = "collegeName";
            this.ddl_College.DataValueField = "collegeName";
            this.ddl_College.DataBind();

            string collegeName = this.ddl_College.SelectedValue;
            this.ddl_Class.DataSource = bllClass.GetClassList(year, collegeName);
            this.ddl_Class.DataTextField = "className";
            this.ddl_Class.DataValueField = "ID";
            this.ddl_Class.DataBind();
        }

        protected void ddl_College_SelectedIndexChanged(object sender, EventArgs e)
        {
            string year = ddl_Year.SelectedValue;
            string collegeName = this.ddl_College.SelectedValue;
            this.ddl_Class.DataSource = bllClass.GetClassList(year, collegeName);
            this.ddl_Class.DataTextField = "className";
            this.ddl_Class.DataValueField = "ID";
            this.ddl_Class.DataBind();
        }
    }
}